// import { use } from 'react'
const fetchData = new Promise((resolve) => {
  setTimeout(() => {
    resolve([1,2,3,4])
  }, 3000);
})
function App() {
  // fetchData 需要是一个promise  如果是一个函数返回一个promise，得保证两次执行的promise是同一个 
  const data = use(fetchData)
  return <div>{data}</div>
}


function use(promise) {
  switch(promise.status) {
    case 'fufilled':
      return promise.value;
    case 'rejected':
      throw promise.reason;
    default:
      throw promise.then(value => {
        promise.status = 'fufilled'
        promise.value = value
      }, reason => {
        promise.status = 'rejected'
        promise.reason = reason
      })
  }
}

export default App